package com.qf.homework.factoryBean;

import org.apache.ibatis.session.*;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.FactoryBean;

import java.io.InputStream;

public class SqlSessionFactoryBean implements FactoryBean<SqlSessionFactory> {
    @Override
    public SqlSessionFactory getObject() throws Exception {
        SqlSessionFactoryBuilder ssfb = new SqlSessionFactoryBuilder();
        InputStream in = this.getClass().getClassLoader().getResourceAsStream("mybatis/mybatis-config.xml");
        return ssfb.build(in);
    }

    @Override
    public Class<?> getObjectType() {
        return SqlSessionFactory.class;
    }

    @Override
    public boolean isSingleton() {
        return true;
    }
}
